//
//  UITableTestViewController.m
//  myfirstapp
//
//  Created by iGxnon on 2021/12/2.
//

#import "UITableTestViewController.h"
#import "UITableViewCellBuilder.h"

@interface UITableTestViewController () <UITableViewDataSource>

@property (strong, nonatomic) UITableView *tableView;

/// 二维数组 arr[section][row] -> cell
@property (copy, nonatomic) NSArray<NSArray<UITableViewCell *> *> *tableViewCells;

@end

@implementation UITableTestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    self.tableView = [[UITableView alloc] initWithFrame: UIScreen.mainScreen.bounds style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
}

/// 懒加载构建 tableViewCells
- (NSArray<NSArray<UITableViewCell *> *> *)tableViewCells {
    UITableViewCellBuilder *builder = [UITableViewCellBuilder Builder];
    if (_tableViewCells == nil) {
        _tableViewCells =
        @[
            @[
                [[builder text:@"1"] build],
                [[builder text:@"2"] build]
            ],
            @[
                [[builder text:@"1"] build],
                [[builder text:@"2"] build],
                [[builder text:@"3"] build],
                [[builder text:@"4"] build],
                [[builder text:@"5"] build],
                [[builder text:@"6"] build]
            ],
            @[
                [[builder text:@"1"] build],
                [[builder text:@"2"] build],
                [[builder text:@"3"] build],
                [[builder text:@"4"] build],
                [[builder text:@"5"] build],
                [[builder text:@"6"] build]
            ],
            @[
                [[builder text:@"1"] build],
                [[builder text:@"2"] build],
                [[builder text:@"3"] build],
                [[builder text:@"4"] build],
                [[builder text:@"5"] build]
            ],
            @[
                [[builder text:@"1"] build],
                [[builder text:@"2"] build],
                [[builder text:@"3"] build],
                [[builder text:@"4"] build]
            ],
            @[
                [[builder text:@"1"] build],
                [[builder text:@"2"] build]
            ]
        ];
    }
    return _tableViewCells;
}

#pragma mark -UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 6;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.tableViewCells[section].count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    return self.tableViewCells[indexPath.section][indexPath.row];
}


@end
